/**
 * Created by ss on 16/4/10.
 */
var $ = require('jquery');
var init = require('../util/init.js');
var util = require('../util/util.js');

require('../../scss/login.scss');
require('../../scss/bottomButton.scss');
init.initNav(true, '');
var urlGet = util.urlGet();
if(util.getUserStore()) {
    util.changePage('index');
}
$("#codeInput .code").attr("src", util.getAjaxUrl('/captchapng'));

$("#loginButton").click(function () {
    var phone = $("#phoneInput input").val();
    var code = $("#codeInput input").val();
    var post = {
        phone: phone,
        code: code
    };
    $.get(util.getAjaxUrl('/users/login'), post, function (data) {
        if (data.code === 1) {
            console.log(urlGet);
            var directUrl = "./index";
            if(urlGet.fromUrl){
                directUrl = decodeURIComponent(urlGet.fromUrl);
            }
            util.setUserStore(data.data);
            util.changePage(directUrl);
        } else {
            alert(data.errorInfo);
        }
    });
});


